﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CoffeeMobile.Models.ViewModels;

namespace CoffeeMobile.Models
{
    public class Repositories
    {
    }
    public interface IBasepository
    {

    }
    public class BaseRepository : IBasepository
    {
        protected CoffeeMobileLinqDataContext _dbLinq;
        public BaseRepository()
        {
            _dbLinq = new CoffeeMobileLinqDataContext();
        }
    }
    public class TablesRepository
    {

    }
    public class TableGroupsRepository : BaseRepository
    {
        public List<TableGroupModel> GetTableGroups()
        {
            List<TableGroupModel> _result = new List<TableGroupModel>();
            _result = (from p in _dbLinq.TableGroups
                       where p.IsDeleted == false
                       select new TableGroupModel
                       {
                           ID = p.ID,
                           Name = p.Name
                       })
                       .OrderBy(p => p.Name)
                       .ToList();
            foreach (TableGroupModel item in _result)
            {
                item.Tables = (from g in _dbLinq.Tables
                               where g.TableGroupID == item.ID
                               select new TableModel
                               {
                                   ID = g.ID,
                                   Name = g.Name
                               }).ToList();
            }
            return _result;
        }
    }
    public class FoodGroupsRepository : BaseRepository
    {
        public List<FoodGroupModel> GetFoodGroups()
        {
            List<FoodGroupModel> result = new List<FoodGroupModel>();
            result = _dbLinq.FoodGroups.Select(p => new FoodGroupModel
            {
                ID = p.ID,
                Name = p.Name
            }).ToList();
            return result;
        }
    }
}